<template>
  <base-layout>
    <template #searchPanel>
      <search-panel
        :addPer="'SystemDict:create'"
        :selectPer="'SystemDict:page'"
        addTitle="新增保险分公司"
        @insert="handleAdd"
        @search="search"
        :showSearchButton="true"
        :showAddButton="true"
      >
        <CitySelect v-model="searchOptions.cityCode" placeholder="城市" />
        <el-form-item prop="status">
          <el-select clearable ref="dragSelect" placeholder="保险分公司名称" v-model="searchOptions.companyName">
            <el-option
              v-for="item in []"
              :key="item.index"
              :value="item.value"
              :label="item.text"
            />
          </el-select>
        </el-form-item>
        <el-select clearable ref="dragSelect" placeholder="所属保险公司" v-model="searchOptions.parentCompanyId">
          <el-option
            v-for="item in []"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="编辑"
            style="cursor: pointer"
            v-permission="'SystemDict:update'"
            @click="handleEdit(row)"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"
            v-permission="'SystemDict:delete'"
            @click="handleDataDelete(row)"
          ></i>
          <i
            class="el-icon-s-order"
            title="保险险种"
            style="cursor: pointer; margin-left: 20px;"
            v-permission="'SystemDict:update'"
            @click="handleViewSpecies(row)"
          ></i>
        </template>
      </data-table>
    </template>
  </base-layout>
</template>
<script>
import baseMixin from '@/mixins/base'
import { 
  dataList, 
  createInsuranceCompany, 
  updateInsuranceCompany, 
  deleteInsuranceCompany 
} from '@/api/after-sale/systemManage/insurance'

export default {
  components: {},
  mixins: [
    baseMixin({
      idName: 'id',
      findData: dataList,
      dataName: ['content', 'totalRecords'],
      addData: createInsuranceCompany,
      updateData: updateInsuranceCompany,
      deleteData: deleteInsuranceCompany,
    }),
  ],
  data () {
    return {
      searchOptions: {
        type: 2
      },
      tableColumnAttributes: [
        {
          name: '保险分公司名称',
          value: 'companyName',
          type: 'text',
        },
        {
          name: '所属保险公司',
          value: 'parentCompanyName',
          type: 'text',
        },
        {
          name: '所属城市',
          value: 'cityName',
          type: 'text',
        },
        {
          name: '所属区县',
          value: 'countyName',
          type: 'text',
        },
        {
          name: '公司地址',
          value: 'address',
          type: 'text',
        },
        {
          name: '主营业务',
          value: 'note',
          type: 'text',
        },
        {
          name: '联系人',
          value: 'contactName',
          type: 'text',
        },
        {
          name: '创建时间',
          value: 'createTime',
          type: 'text',
        },
      ],
    }
  },
  created () { },
  methods: {
    handleAdd() {
      this.$router.push({ path: '/systemManage/insuranceManage/addBranchCompany' })
    },
    handleEdit(row) {
      this.$router.push({
        path: '/systemManage/insuranceManage/addBranchCompany',
        query: {
          id: row.id,
        },
      })
    },
    // 查询
    search () {
      this.searchOptions = this.form
      this.currentPage = 1
      this.setTableData()
    },
    //查看保险险种
    handleViewSpecies(row) {
      this.$router.push({
        path: '/systemManage/insuranceManage/species',
        query: {
          id: row.id,
          companyName: row.companyName
        },
      })
    },
  },
  mounted () {},
}
</script>
